<?php
namespace App\Entity;

use App\Models\User as UserModel;

/**
* 当前登录的用户实体
*/
class UserEntity extends EntityBase 
{
    # 当前选择的站点id
    protected $site_id;
    # 本地权限分组
    protected $group;
    
    # $user :: int | UserModel
    public function __construct($user = null){
        if(is_integer($user)) {
            $um = UserModel::find($user);
            if(!$um)
                throw new \Exception("用户不存在", 1);
            $this->setModel($um);
        } else if($user instanceof UserModel) {
            $this->setModel($user);
        }
    }
    
    public function __get($property){
        if(isset($this->$property))
            return $this->$property;
    
        return parent::__get($property);
    }
    
    public function __set($property, $val){
        if($property == 'site_id'){
            $this->site_id = $val;
            //$this->group = $this->calcGroup();
        }
        parent::__set($property, $val);
    }
    
    
}